package struts.actions;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import struts.model.User;
import struts.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

@Component
public class UserAction extends ActionSupport {

	private UserService userService;
	private List<User> users;
	private User user;
	private int id;
	
	public String list(){
		users = userService.listAll();
		return SUCCESS;
	}
	
	public String add(){
		userService.add(user);
		return SUCCESS;
	}
	
	public String delete(){
		userService.remove(user);
		return SUCCESS;
	}
	
	public String update(){
		User user = new User();
		user.setId(id);
		userService.update(user);
		return SUCCESS;
	}
	
	public String updateInput(){
		user = userService.list(id);		
		return INPUT;
	}
	
	public String addInput(){
		return INPUT;
	}
	
	public List<User> getUsers() {
		return users;
	}
	
	public void setUsers(List<User> users) {
		this.users = users;
	}
	
	public UserService getUserService() {
		return userService;
	}
	
	@Resource
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public User getUser() {
		return user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
}
